/*
 * Copyright 2011 Dim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.ratingviewer.data;

import java.text.MessageFormat;

public class Player {

	private final long id;

	private final int rank;
	private final String name;

	private String title;

	private int rating;
	private int quickChessRating;

	private int gamesCount;
	private int winCount;
	private int defeatCount;
	private int drawnCount;

	private long lastGameTime;

	public Player(long id, int rank, String name) {
		super();

		this.id = id;

		if (rank <= 0)
			throw new IllegalArgumentException(MessageFormat.format("Player (ID={0}) rank can''t be less or "
					+ "equal ZERO.", id));
		this.rank = rank;

		if (name == null)
			throw new IllegalArgumentException(MessageFormat.format("Player (ID={0}) name can''t be null.", id));
		this.name = name;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getRating() {
		return rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public int getQuickChessRating() {
		return quickChessRating;
	}

	public void setQuickChessRating(int quickChessRating) {
		this.quickChessRating = quickChessRating;
	}

	public int getGamesCount() {
		return gamesCount;
	}

	public void setGamesCount(int gamesCount) {
		this.gamesCount = gamesCount;
	}

	public int getWinCount() {
		return winCount;
	}

	public void setWinCount(int winCount) {
		this.winCount = winCount;
	}

	public int getDefeatCount() {
		return defeatCount;
	}

	public void setDefeatCount(int defeatCount) {
		this.defeatCount = defeatCount;
	}

	public int getDrawnCount() {
		return drawnCount;
	}

	public void setDrawnCount(int drawnCount) {
		this.drawnCount = drawnCount;
	}

	public long getLastGameTime() {
		return lastGameTime;
	}

	public void setLastGameTime(long lastGameTime) {
		this.lastGameTime = lastGameTime;
	}

	public long getId() {
		return id;
	}

	public int getRank() {
		return rank;
	}

	public String getName() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Player other = (Player) obj;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return rank + "." + name + " (" + id + ")";
	}

}
